
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @author: guojianbo
* @since: 2022-04-23 12:45:29
*/
var log_1 = __webpack_require__(/*! ../utils/log */ "./src/extra/utils/log.ts");
var map_1 = __webpack_require__(/*! _Eutils/map */ "./src/extra/utils/map.ts");
var analytics_1 = __webpack_require__(/*! _util/analytics */ "./src/core/utils/analytics.ts");
var constant_1 = __webpack_require__(/*! ../../core/utils/constant */ "./src/core/utils/constant.ts");
var report_util_1 = __webpack_require__(/*! ../../core/statistics/report-util */ "./src/core/statistics/report-util.ts");
var deviceInfo_1 = __webpack_require__(/*! ../../core/utils/deviceInfo */ "./src/core/utils/deviceInfo.ts");
var MessageReport = /** @class */ (function () {
    function MessageReport() {
        this._queueMap = new map_1.default();
    }
    MessageReport.prototype.hasMessage = function (uuid) {
        if (uuid === void 0) { uuid = ''; }
        return this._queueMap.has(uuid);
    };
    MessageReport.prototype.getMessage = function (uuid) {
        if (uuid === void 0) { uuid = ''; }
        if (this._queueMap.has(uuid)) {
            return this._queueMap.get(uuid);
        }
        return null;
    };
    MessageReport.prototype.putMessage = function (_a) {
        var message = _a.message, start = _a.start;
        this._queueMap.set(message.uuid, { message: message, start: start });
    };
    MessageReport.prototype.deleteQueueMessage = function (uuid) {
        if (uuid === void 0) { uuid = ''; }
        if (this._queueMap.has(uuid)) {
            return this._queueMap.delete(uuid);
        }
        return false;
    };
    MessageReport.prototype.getReportMsgCategory = function (message) {
        if (!message) {
            return;
        }
        if (message.sessionType === constant_1.SESSION_TYPE.CHAT || message.sessionType === constant_1.SESSION_TYPE.CHAT2) {
            return report_util_1.REPORT_MSG_CATEGORY.PERSON;
        }
        else if (message.sessionType === constant_1.SESSION_TYPE.GROUP_CHAT) {
            return report_util_1.REPORT_MSG_CATEGORY.GROUP;
        }
        else if (message.sessionType === constant_1.SESSION_TYPE.PUB_CHAT || message.sessionType === constant_1.SESSION_TYPE.PUB_CHAT2
            || message.sessionType === constant_1.SESSION_TYPE.CS_CHAT || message.sessionType === constant_1.SESSION_TYPE.CS_CHAT2) {
            return report_util_1.REPORT_MSG_CATEGORY.PUB;
        }
        else {
            return -1;
        }
    };
    MessageReport.prototype.getReportResult = function (message) {
        if (!message) {
            return;
        }
        var resultReport = 0;
        if (message.status == constant_1.MESSAGE_STATUS.STATUS_ACK) {
            resultReport = 0;
        }
        else {
            resultReport = message.status;
        }
        return resultReport;
    };
    MessageReport.prototype.getReportTime = function (message) {
        if (!message) {
            return;
        }
        var result = Date.now() - this.getMessage(message.uuid).start;
        if (result > 5000) {
            result = 5000;
        }
        return result;
    };
    MessageReport.prototype.reportMessageStart = function (message) {
        try {
            if (!message) {
                return;
            }
            this.putMessage({ message: message, start: Date.now() });
        }
        catch (error) {
            log_1.default.error('MessageReport::reportMessageStart error:' + error);
            return;
        }
    };
    MessageReport.prototype.reportMessageEnd = function (message) {
        try {
            if (!message) {
                return;
            }
            if (message && message.isCancel) {
                return;
            }
            if (!this.hasMessage(message.uuid)) {
                return;
            }
            if (message.status == constant_1.MESSAGE_STATUS.STATUS_CREATED || message.status == constant_1.MESSAGE_STATUS.STATUS_SENT) {
                return;
            }
            analytics_1.default.report({
                nm: 'sendmessage',
                val: {
                    result: this.getReportResult(message),
                    msg: '',
                    msgtype: message.type,
                    msgcategory: this.getReportMsgCategory(message),
                    mid: message.mid,
                    id: message.uuid,
                    time: this.getReportTime(message),
                    retries: 0,
                    net: report_util_1.REPORT_NET_TYPE,
                    chatid: message.sessionId,
                    chid: message.channelId,
                    code: message.sendCode,
                    status: deviceInfo_1.default.isHasNetwork() ? 0 : 1,
                }
            });
            return;
        }
        catch (error) {
            log_1.default.error('MessageReport::reportMessageEnd error:' + error);
            return;
        }
    };
    return MessageReport;
}());
exports.default = new MessageReport();


//# sourceURL=webpack://MTDX/./src/extra/statistics/message-report.ts?